<?php
//
// Article Comment Class
// The SDMworld! Network
//

class cObj4c5e4ce031e211dba98b0800200c9a66 extends cDycmsObject
{
	function Edit()
	{
		if(!$this->Validate(S_MODIFY))
			return EAUTH;
		if($this->mId)
		{
			if($_GET['$editor-action'] == 'delete')
			{
				if(!$this->Validate(S_SPECIAL))
					return EAUTH;
				else
				{
					if(dbDeleteObject($this->mClsId, $this->mId))
					{
						echo uiIcon("info", false)."Object deleted";
						$this->mId = 0;
						$this->LoadObject(NULL);
						print("<h2>Editing New Object [".$this->mClsId."]</h2>\n");
					}
					else
						return EDB;
				};
			}
			//
			// We are editing existing
			//
			
			if(count($_POST))
			{
				$c = $this->DoEdit($_POST);
				if($c < 0)
					return $c;
				else
				{
					header("location: ".html_entity_decode(dyViewerUrl('19a61440317911dba98b0800200c9a66',$_POST['articleid'])));
					return $c;
				};
			};
			
?>			
<!-- START EDITOR -->
<form action="" method="post" name="editor">
<table class="editor">
<tr>
<td>Title</td>
<td><input type="text" name="title" value=<?php echo("\"{$this->mAttributes['title']}\""); ?> /></td>
</tr><tr>
<td colspan="2">Your Comment:</td>
</tr><tr>
<td colspan="2"><textarea name="body"><?php echo("{$this->mAttributes['body']}"); ?></textarea></td>
</tr>
</table>
<input type="hidden" name="articleid" value=<?php echo("\"{$this->mAttributes['articleid']}\""); ?> />
<input type="hidden" name="date" value=<?php echo("\"{$this->mAttributes['date']}\""); ?> />
<input type="submit" value="Edit Comment" />
<input type="reset" value="Reset" />
</form>
<!-- END EDITOR -->
<?php	
		}
		else
		{
			//
			// This is a new object - get public token
			//
			
			$this->mToken = $GLOBALS['gClient']->GetToken($this->mClsId, 'public');
			if(!$this->mToken)
				return EAUTH;
			else if(!$this->mSecurity->Read($this->mToken))
				return EUNKNOWN;
			
			if(count($_POST))
			{
				$vz = $_POST;
				$vz['date'] = date('Y-m-d H:i:s');
				
				$c = $this->DoEdit($vz);
				if($c < 0)
					return $c;
				else
				{
					header("location: ".html_entity_decode(dyViewerUrl('19a61440317911dba98b0800200c9a66',$_POST['articleid'])));
					return $c;
				};
			};

			$articleid = urldecode($_GET['articleid']);
			if(!$articleid || !ctype_digit($articleid))
				return EINVALIDARGS;
			$article = dyLoadObject('19a61440317911dba98b0800200c9a66',$articleid);
			if(!is_object($article))
				return $article;
?>			
<!-- START EDITOR -->
<form action="" method="post" name="editor">
<table>
<tr>
<td>Title</td>
<td><input type="text" name="title" value=<?php echo("\"Re: {$article->Get('title')}\""); ?> /></td>
</tr><tr>
<td colspan="2">Your Comment:</td>
</tr><tr>
<td colspan="2"><textarea name="body"></textarea></td>
</tr>
</table>
<input type="hidden" name="articleid" value=<?php echo("\"$articleid\""); ?> />
<input type="submit" value="Post Comment" />
</form>
<!-- END EDITOR -->
<?php	
		}
	}
	
	function Render()
	{
		$buf = "<div class='article-comment-header'><div style='float:left'>{$this->mAttributes['title']}</div>".
			"<div style='float: right'>{$this->mAttributes['date']}</div>".
			"<div style='visibility:hidden'>{$this->mAttributes['title']}</div></div>\n";
		$buf .= "<div class='article-comment-body'>{$this->mAttributes['body']}</div>\n".
			"<div class='article-comment-footer'><div style='float:right'>".
			($this->Validate(S_MODIFY)?"<a href='".dyEditorUrl($this->mClsId, $this->mId)."'>Edit</a>":'').
			($this->Validate(S_SPECIAL)?" | <a href='".dyEditorUrl($this->mClsId, $this->mId, 
				array('$editor-action'=>'delete'))."'>Delete</a>":'')."</div>".
			"Posted by ...".
			"</div>";
		
		return $buf;
	}
	
	function GetSummary()
	{
		return $this->mAttributes['title'];
	}
	
	function LoadObject($vzAttrib)
	{
		if($vzAttrib)
			$this->mAttributes = $vzAttrib;
		else
		{
			$this->mAttributes['articleid'] = "";
			$this->mAttributes['title'] = "";
			$this->mAttributes['date'] = "";
			$this->mAttributes['body'] = "";
		};
		
		$this->mValueAttributes['body'] = &$this->mAttributes['body'];
		$this->mIndexAttributes['title'] = &$this->mAttributes['title'];
		$this->mIndexAttributes['date'] = &$this->mAttributes['date'];
		$this->mIndexAttributes['articleid'] = &$this->mAttributes['articleid'];
	}
}

class cCollection4c5e4ce031e211dba98b0800200c9a66 extends cDycmsAbstractCollection
{
	function GetDisplay($i = -1)
	{
		if($i > -1)
			return $this->mObject[$i]->GetDisplay();
		
		$buf = "<h2>Comments ";
		if($this->mCriteria['articleid'])
		{
			$buf.=  "<a href='".dyEditorUrl('4c5e4ce031e211dba98b0800200c9a66', NULL, 
				array('articleid'=>$this->mCriteria['articleid']))."'>(Post New)</a>";
		};
		$buf .= "</h2>";
		
		foreach($this->mObject as $obj)
		{
			$buf .= "<div class='article-comment'>".$obj->GetDisplay()."</div>";
		}
		
		return $buf;
	}
	
	public function GetSummary($i = -1)
	{
		if($i > -1)
			return $this->mObject[$i]->GetSummary();
			
		$vz = $this->GetUniqueValues('site');
		$n = count($vz);
		if($n != 1)
			return "Articles";
		$buf = "/ {$vz[0]}";
		
		$vz = $this->GetUniqueValues('category');
		$n = count($vz);
		if($n != 1)
			return $buf;
		$buf .= " / {$vz[0]}";
		return $buf;
	}
}

?>